package com.ruoyi.web.controller.work;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.work.domain.WorkSeal;
import com.ruoyi.work.service.IWorkSealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 印章管理Controller
 *
 * @author fengcheng
 * @date 2025-03-17
 */
@RestController
@RequestMapping("/work/seal")
public class WorkSealController extends BaseController {
    @Autowired
    private IWorkSealService workSealService;

    /**
     * 查询印章管理列表
     */
    @PreAuthorize("@ss.hasPermi('work:seal:list')")
    @GetMapping("/listWorkSealVo")
    public AjaxResult listWorkSealVo(WorkSeal workSeal) {
        List<WorkSeal> list = workSealService.selectWorkSealList(workSeal);
        return success(list);
    }

    /**
     * 查询印章管理列表
     */
    @PreAuthorize("@ss.hasPermi('work:seal:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkSeal workSeal) {
        startPage();
        List<WorkSeal> list = workSealService.selectWorkSealList(workSeal);
        return getDataTable(list);
    }

    /**
     * 导出印章管理列表
     */
    @PreAuthorize("@ss.hasPermi('work:seal:export')")
    @Log(title = "印章管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkSeal workSeal) {
        List<WorkSeal> list = workSealService.selectWorkSealList(workSeal);
        ExcelUtil<WorkSeal> util = new ExcelUtil<WorkSeal>(WorkSeal.class);
        util.exportExcel(response, list, "印章管理数据");
    }

    /**
     * 获取印章管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('work:seal:query')")
    @GetMapping(value = "/{suraId}")
    public AjaxResult getInfo(@PathVariable("suraId") Long suraId) {
        return success(workSealService.selectWorkSealBySuraId(suraId));
    }

    /**
     * 新增印章管理
     */
    @PreAuthorize("@ss.hasPermi('work:seal:add')")
    @Log(title = "印章管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkSeal workSeal) {
        return toAjax(workSealService.insertWorkSeal(workSeal));
    }

    /**
     * 修改印章管理
     */
    @PreAuthorize("@ss.hasPermi('work:seal:edit')")
    @Log(title = "印章管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkSeal workSeal) {
        return toAjax(workSealService.updateWorkSeal(workSeal));
    }

    /**
     * 删除印章管理
     */
    @PreAuthorize("@ss.hasPermi('work:seal:remove')")
    @Log(title = "印章管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{suraIds}")
    public AjaxResult remove(@PathVariable Long[] suraIds) {
        return toAjax(workSealService.deleteWorkSealBySuraIds(suraIds));
    }
}
